#if 1

#include <stdint.h>

#include "BooterConfig.h"
//	#include "Bkp.h"
#include "Flash.h"

static void Booter_WriteUpgradeFlag(uint32_t Flag);
static uint32_t Booter_ReadUpgradeFlag(void);


#define LPWRRSTF	31
#define WWDGRSTF	30
#define IWDGRSTF	29
#define SFTRSTF		28
#define PORRSTF		27
#define PINRSTF		26

#define MASK(RSTF) (1u << (RSTF))
#define INTER_RST_MASK() (MASK(LPWRRSTF)|MASK(WWDGRSTF)|MASK(IWDGRSTF)|MASK(SFTRSTF)|MASK(PORRSTF))

static int Booter_OtherReset(void){
#if 0
	static const uint8_t resetFlag[] = {
		RCC_FLAG_PORRST,
		RCC_FLAG_SFTRST,
		RCC_FLAG_IWDGRST,
		RCC_FLAG_WWDGRST,
		RCC_FLAG_LPWRRST,
		0
	};

	const uint8_t* flag = resetFlag;
	while(*flag){
		if(RCC_GetFlagStatus(*flag)){
			return 1;
		}
		flag++;
	}
#endif 
	return 0;
}

uint32_t Booter_IsExternReset(void) {
#if 0
    uint32_t CSR = RCC->CSR;

    RCC_ClearFlag();

    if(CSR & INTER_RST_MASK()) {
        return 0;
    }

    if(CSR & MASK(PINRSTF)) {
        return 1;
    }
#endif 
#if 0
    unsigned int status = 0;
    
	if(Booter_OtherReset()){
		status = 0;
	}
    else
    if(RCC_GetFlagStatus(RCC_FLAG_PINRST)){
        status = 1;
    }
	RCC_ClearFlag();
    return status;
#endif 
	return 0;
}



uint32_t Booter_IsAppCompelet(void){
	return Flash_ReadAppCompeletFlag() == (uint32_t)~0u;
}

uint32_t Booter_ClearAppCompeletFlag(void){
	//return Flash_WriteAppCompeletFlag(0);
  return 1;
}

uint32_t Booter_SetAppCompeletFlag(void){
	//return Flash_WriteAppCompeletFlag(~0);
  return 1;
}



uint32_t Booter_IsBootFail(void){
	return 0;
}

void Booter_BootFailFlag(void){
//		Bkp_Write(BKP_DR2, 0xAA55);
}

void Booter_BootFailClear(void){
//		Bkp_Write(BKP_DR2, 0x0000);
}

static void Booter_WriteUpgradeFlag(uint32_t Flag) {
}
static uint32_t Booter_ReadUpgradeFlag(void) {
	return 0;
}

uint32_t Booter_IsUpgradeFlaged(void){
	return Booter_ReadUpgradeFlag() == 0xAA55AA55;
}
void Booter_ClearUpgradeFlag(void) {
    Booter_WriteUpgradeFlag(0);
}

#endif 

